
	import util from '@/libs/util';
	import spr from '@/sprcore/common';
	export default {
		data() {
			return {
				columns: [{
						title: '会议室',
						key: 'roomName'
					},
					{
						title: '容纳人数',
						key: 'maxPerson'
					},
					{
						title: '大楼',
						key: 'buildingName'
					},
					{
						title: '区域',
						key: 'regionName'
					},
					{
						title: 'Action',
						key: 'action',
						width: 150,
						align: 'center',
						render: (h, params) => {
							return h('div', [
								h('Button', {
									props: {
										type: 'primary',
										size: 'small'
									},
									style: {
										marginRight: '5px'
									},
									on: {
										click: () => {
											let that = this;
											that.form_updateMeetRoom(that.list_datas[params.index].id);
										}
									}
								}, '查看编辑'),
								h('Button', {
									props: {
										type: 'error',
										size: 'small'
									},
									on: {
										click: () => {
											let that = this;
											//that.remove(params.index);
							                this.$Modal.confirm({
							                    title: '操作提示',
							                    content: '<p>确认是否删除此记录</p>',
							                    onOk: () => {
							                        that.form_handleDelete(that.list_datas[params.index].id);
							                    },
							                    onCancel: () => {
							                    }
							                });											
										}
									}
								}, '删除')
							]);
						}
					}
				],
				list_searchKey:'',
				list_datas: [],
				list_totalCount: 0,
				list_pageSize:spr.constants.list_pageSize,
				list_pageNo:1,
				
				form_createOrUpdateModalLoading: true,
				form_createOrUpdateModal: false,
				form_createOrUpdateModalTitle: '',
				form_createOrUpdateItemForm: {
					id: '',
					buildingregionId: '',
					roomName: '',
					maxPerson: '',
					allowAnonybook: '',
					onlyallowHuiwubook: '',
					memo: '',
					fileImage: ''
				},
				form_createOrUpdateItemFormRuleValidate: {
					buildingregionId: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					}],
					roomName: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					}],
					maxPerson: [{
						required: true,
						message: '不能为空',
						trigger: 'blur'
					},{pattern:spr.pattern.number,message:'请输入数字',trigger:'change'}],					
				},
				form_loading_buildingregionId:false	,
				formdata_buildingregionList:[],
				
				dict_YN:[],
				
			}
		},
		methods: {
			list_getData() {
				let that = this;
				//alert(that.list_pageSize+"/"+that.list_pageNo+"/"+(that.list_pageSize * ( that.list_pageNo - 1)));
				util.ajax.get('/api/boardroom/list', {
					params: {
						size: that.list_pageSize,
						offset: that.list_pageSize * ( that.list_pageNo - 1),
						searchKey: that.list_searchKey
					}
				}).then(function(response) {
					that.list_datas = response.data.datas;
					that.list_totalCount = response.data.totalCount;
				}).catch(function(error) {
					spr.errNotify(that,error);
				});
				
				util.ajax.get('/api/core/dict/listDictValue', {
					params: {
						setCode:'YN'
					}
				}).then(function(response) {
					that.dict_YN = response.data.datas;
				}).catch(function(error) {
					spr.errNotify(that,error);
				});				
				
			},
			list_searchMeetRoom(){
				let that = this;
				that.list_getData();
			},
			list_changePage(pageNo){
				let that = this;
				that.list_pageNo = pageNo;
				that.list_getData();
			},		
			list_changePageSize(pageSize){
				let that = this;
				that.list_pageSize = pageSize;
				that.list_getData();
			},				
			list_remove(index) {
				let that = this;
				that.data6.splice(index, 1);
			},
			
			form_init() {
				let that = this;

				that.form_createOrUpdateModalLoading = true;
				that.form_createOrUpdateModal = true;
				
				that.form_createOrUpdateItemForm.id = '';
				that.form_createOrUpdateItemForm.buildingregionId = '';
				that.form_createOrUpdateItemForm.roomName = '';
				that.form_createOrUpdateItemForm.maxPerson = '';
				that.form_createOrUpdateItemForm.allowAnonybook = '';
				that.form_createOrUpdateItemForm.onlyallowHuiwubook = '';
				that.form_createOrUpdateItemForm.memo = '';
				that.form_createOrUpdateItemForm.fileImage = '';
				
				//that.buildingregionList = [{key: '1',value: 'New York'},{key: '2',value: 'Shanghai'}];
				util.ajax.get('/api/common/listBuildingregion', {
					params: {}
				}).then(function(response) {
					that.formdata_buildingregionList = response.data.datas;
				}).catch(function(error) {
					spr.errNotify(that,error);
				});				
				
			},
			form_createMeetRoom() {
				let that = this;
				that.form_init();
				that.form_createOrUpdateModalTitle = "新增会议室";
			},
			form_updateMeetRoom(id) {
				let that = this;
				that.form_init();
				that.form_createOrUpdateModalTitle = "修改会议室";

				util.ajax.get('/api/boardroom/get', {
					params: {
						id: id
					}
				}).then(function(response) {
					//alert(response.data.roomName);
					let data = response.data;
					that.form_init();
					
					that.form_createOrUpdateItemForm.id = data.id;
					that.form_createOrUpdateItemForm.buildingregionId = data.buildingregionId;
					that.form_createOrUpdateItemForm.roomName = data.roomName;
					that.form_createOrUpdateItemForm.maxPerson = data.maxPerson;
					that.form_createOrUpdateItemForm.allowAnonybook = data.allowAnonybook;
					that.form_createOrUpdateItemForm.onlyallowHuiwubook = data.onlyallowHuiwubook;
					that.form_createOrUpdateItemForm.memo = data.memo;
					that.form_createOrUpdateItemForm.fileImage = data.fileImage;
				}).catch(function(error) {
					spr.errNotify(that,error);
				});
			},
			form_handlecreateOrUpdateItemForm() {
				let that = this;
				that.form_createOrUpdateModal = true;
				that.$refs['form_createOrUpdateItemForm'].validate((valid) => {
					if(!valid) {
						that.form_createOrUpdateModalLoading = false;
						that.$nextTick(() => {that.form_createOrUpdateModalLoading = true;});
					} else {
						util.ajax.post('/api/boardroom/createOrUpdate', {
							id: that.form_createOrUpdateItemForm.id,
							buildingregionId: that.form_createOrUpdateItemForm.buildingregionId,
							roomName: that.form_createOrUpdateItemForm.roomName,
							maxPerson: that.form_createOrUpdateItemForm.maxPerson,
							allowAnonybook: that.form_createOrUpdateItemForm.allowAnonybook,
							onlyallowHuiwubook: that.form_createOrUpdateItemForm.onlyallowHuiwubook,
							memo: that.form_createOrUpdateItemForm.memo
						}).then(function(response) {
							that.$Message.info('保存成功!');
							that.form_createOrUpdateModal = false;
							that.list_getData();
						}).catch(function(error) {
							spr.errNotify(that,error);
						});
					}
				});
			},
			form_handleDelete(id){
				let that = this;
				util.ajax.post('/api/boardroom/delete', {
					id: id
				}).then(function(response) {
					that.$Message.info('记录删除成功!');
					that.list_getData();
				}).catch(function(error) {
					console.log(error);
				});				
			},

			form_getBuildingregionList(query){
				let that = this;
				that.loading_buildingregionId = true;
				util.ajax.get('/api/common/listBuildingregion', {
					params: {
						searchKey:query
					}
				}).then(function(response) {
					that.formdata_buildingregionList = response.data.datas;
					that.loading_buildingregionId = false;
				}).catch(function(error) {
					spr.errNotify(that,error);
				});					
                			
			}
		},
		created() {
			let that = this;
			that.list_getData();
		}
	}